import { defineStore } from 'pinia'
import { setting } from '@/api/book'
import { ElMessage } from 'element-plus'

export const useSettingStore = defineStore('setting', {
    state: () => ({
        current: {
            id: '',
            logo: '',
            logo_name: '',
            name: ''
        }
    }),
    persist: {
        enabled: true,
        //需要缓存的数据
        strategies: [
            {
                key: "current",
                paths: ["current"],
                storage: sessionStorage
            }
        ],
    },
    getters: {

    },
    actions: {
        getSetting() {
            setting().then(res => {
                if (res.data.code === 200) {
                    this.current.id = res.data.setting.id
                    this.current.logo = res.data.setting.logo
                    this.current.logo_name = res.data.setting.logo_name
                    this.current.name = res.data.setting.name
                } else {
                    ElMessage.error(res.data.message)
                }
            })
        }
    }
})
